package view
{	
	import event.SendNameEvent;
	
	import mx.events.FlexEvent;
	
	import spark.components.TextInput;
	import spark.components.supportClasses.SkinnableComponent;
	
	[Event(name="sendName", type="event.SendNameEvent")]
	public class NameInput extends SkinnableComponent
	{
		
		[SkinPart] public var nameTextInput:TextInput;
		
		override protected function getCurrentSkinState():String
		{
			return super.getCurrentSkinState();
		} 
		
		override protected function partAdded(partName:String, instance:Object) : void
		{
			super.partAdded(partName, instance);
			
			if (instance == nameTextInput)
			{
				nameTextInput.addEventListener(FlexEvent.ENTER, handleSendName);
			}
		}
		
		public function handleSendName(e:FlexEvent):void
		{
			dispatchEvent(new SendNameEvent(SendNameEvent.SENDNAME, nameTextInput.text.toString()));
		}
		
		override protected function partRemoved(partName:String, instance:Object) : void
		{
			super.partRemoved(partName, instance);
		}
	}
}